package com.ruoyi.zhmk.controller;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.zhmk.domain.request.SendPersonRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkPerson;
import com.ruoyi.zhmk.service.IZhmkPersonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员信息Controller
 * 
 * @author ruoyi
 * @date 2021-06-24
 */
@Api("人员信息管理")
@RestController
@RequestMapping("/zhmk/person")
public class ZhmkPersonController extends BaseController
{
    @Autowired
    private IZhmkPersonService zhmkPersonService;

    /**
     * 查询人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:person:list')")
    @GetMapping("/list")
    @DataScope(deptAlias = "zhmk_person")
    public TableDataInfo list(ZhmkPerson zhmkPerson)
    {
        startPage();
        List<ZhmkPerson> list = zhmkPersonService.selectZhmkPersonList(zhmkPerson);
        return getDataTable(list);
    }

    /**
     * 导出人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:person:export')")
    @Log(title = "人员信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZhmkPerson zhmkPerson)
    {
        List<ZhmkPerson> list = zhmkPersonService.selectZhmkPersonList(zhmkPerson);
        ExcelUtil<ZhmkPerson> util = new ExcelUtil<ZhmkPerson>(ZhmkPerson.class);
        return util.exportExcel(list, "人员信息数据");
    }

    /**
     * 获取人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:person:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zhmkPersonService.selectZhmkPersonById(id));
    }

    /**
     * 新增人员信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:person:add')")
    @Log(title = "人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhmkPerson zhmkPerson)
    {
        return toAjax(zhmkPersonService.insertZhmkPerson(zhmkPerson));
    }

    /**
     * 修改人员信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:person:edit')")
    @Log(title = "人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhmkPerson zhmkPerson)
    {
        return toAjax(zhmkPersonService.updateZhmkPerson(zhmkPerson));
    }

    /**
     * 删除人员信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:person:remove')")
    @Log(title = "人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhmkPersonService.deleteZhmkPersonByIds(ids));
    }

    /**
     * 人员下发
     * @return
     */
    @ApiOperation("人员下发")
    @PostMapping("/personSend")
    public AjaxResult personSend(@RequestBody SendPersonRequest sendPersonRequest){
        return zhmkPersonService.personSend(sendPersonRequest);
    }

    /**
     * 查询所有人员
     * @return
     */
    @ApiOperation("查询全部人员")
    @GetMapping("/findAll")
    @DataScope(deptAlias = "zhmk_person")
    public AjaxResult findAll(ZhmkPerson zhmkPerson){
        return AjaxResult.success(zhmkPersonService.selectZhmkPersonList(zhmkPerson));
    }
}
